home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / net.h < prev    next >
C/C++ Source or Header  |  1990-10-26  |  7KB  |  233 lines

  1. /*
  2.  * net.h --
  3.  *
  4.  *    Declarations of the network library code.
  5.  *
  6.  * Copyright 1987 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Header: /sprite/src/lib/include/RCS/net.h,v 1.10 90/10/19 15:50:56 jhh Exp $ SPRITE (Berkeley)
  16.  */
  17.  
  18. #ifndef _NET_USER
  19. #define _NET_USER
  20.  
  21. #include "machparam.h"
  22. #include "netEther.h"
  23. #include "netInet.h"
  24. #include "netUltra.h"
  25. #include "sprite.h"
  26.  
  27. /*
  28.  * A network address.  The "generic" field must be at least as large as
  29.  * any of the other fields.
  30.  */
  31. typedef union Net_Address {
  32.     Net_EtherAddress        ether;
  33.     Net_InetAddress        inet;
  34.     Net_UltraAddress        ultra;
  35.     struct { char data[8]; }     generic;
  36. } Net_Address;
  37.  
  38. /*
  39.  * Macro to compare two Net_Address objects.
  40.  */
  41. #define NET_ADDRESS_COMPARE(a,b) \
  42.     (bcmp((char *) &(a), (char *) &(b), sizeof(Net_Address)))
  43.  
  44. /*
  45.  * Maximum number of network protocols.  Right now we support two,
  46.  * raw (ethernet for example) and inet
  47.  */
  48.  
  49. #define NET_MAX_PROTOCOLS 2
  50.  
  51. /*
  52.  * The different protocols.
  53.  */
  54.  
  55. #define NET_PROTO_RAW    0
  56. #define NET_PROTO_INET    1
  57.  
  58.  
  59. /* 
  60.  * This is the version number stored in the route.  Set this before
  61.  * installing a route and check it when looking at one.
  62.  */
  63. #define NET_ROUTE_VERSION 0x70500
  64.  
  65. /*
  66.  * Number of different types of networks. 
  67.  */
  68.  
  69. #define NET_NUM_NETWORK_TYPES 2
  70.  
  71. /*
  72.  * Type of network.  See below.
  73.  */
  74.  
  75. typedef int Net_NetworkType;
  76.  
  77. /*
  78.  * Types of network (values for Net_NetworkType).
  79.  */
  80.  
  81. #define NET_NETWORK_ETHER    ((Net_NetworkType) 0)    /* Ethernet. */
  82. #define NET_NETWORK_ULTRA    ((Net_NetworkType) 1)    /* Ultranet. */
  83.  
  84. /*
  85.  * This structure defines the packet headers.
  86.  */
  87. typedef union Net_Header {
  88.     Net_EtherHdr    etherHdr;    /* Raw ethernet packet. */
  89.     struct {                /* An IP packet on the ethernet. */
  90.     Net_EtherHdr    etherHdr;
  91.     Net_IPHeader    ipHdr;
  92.     } inetHdr;        
  93. } Net_Header;
  94.  
  95. /*
  96.  * The user-level view of a route. This structure is used to both install
  97.  * routes and to get their contents.  The fields are marked 'in' if they
  98.  * must be set to install a route, and 'out' if they are set when 
  99.  * getting a route's contents.
  100.  */
  101.  
  102. typedef struct Net_RouteInfo {
  103.     int            version;    /* Version number. (in/out)*/
  104.     int            spriteID;    /* Sprite ID of route target. (in/out)*/
  105.     int            interface;    /* The interface number to use. 
  106.                      * (in/out) */
  107.     int            protocol;    /* Route protocol. (in/out) */
  108.     int            flags;        /* Flags. See below. (in/out) */
  109.     int            refCount;    /* Number of references to route. 
  110.                      * (out). */
  111.     int            routeID;    /* Unique route ID. (in/out)*/
  112.     int            maxBytes;    /* Maximum transfer unit for route. 
  113.                      * This does not include any headers.
  114.                      * (out) */
  115.     int            minBytes;    /* Minimum transfer unit for route. 
  116.                      * This does not include any headers.
  117.                      * (out) */
  118.     Net_NetworkType    netType;    /* Type of network. See above. (out) */
  119.     Net_Address        netAddress[NET_MAX_PROTOCOLS];    /* Address of target
  120.                              * for each protocol.
  121.                                (in/out) */
  122.     char        desc[64];    /* Route description for debugging.
  123.                      * (out) */
  124.     char        hostname[20];    /* Host name. (in/out) */
  125.     char        machType[12];    /* Host machine type. (in/out) */
  126.     ClientData        userData;    /* Data that is uninterpreted by 
  127.                      * kernel. (in/out) */
  128.     Net_Header        header;        /* The packet header. (out) */
  129. } Net_RouteInfo;
  130.  
  131.  
  132. /*
  133.  * Define the flags field.
  134.  */
  135.  
  136. #define NET_FLAGS_VALID 0x1
  137.  
  138. /*
  139.  * Define the special Sprite ID used for broadcasting.
  140.  */
  141. #define        NET_BROADCAST_HOSTID    0
  142.  
  143.  
  144. /* 
  145.  * If we're building a kernel, don't include this declaration.  It 
  146.  * clashes with the declaration for the real kernel routine.
  147.  */
  148.  
  149. #ifndef KERNEL
  150.  
  151. extern ReturnStatus Net_InstallRoute _ARGS_((int spriteID, int flags,
  152.                          int type, ClientData clientData,
  153.                          char *hostname, char
  154.                          *machType));
  155.  
  156. #endif /* KERNEL */
  157.  
  158. /* 
  159.  * The structures defined below here are obsolete and should not be used
  160.  * in new programs.
  161.  */
  162.  
  163. /*
  164.  * A Generic network address...
  165.  */
  166. typedef struct {
  167.     char    data[14];
  168. } Net_GenericAddress;
  169.  
  170. /*
  171.  * Definition of user visible Route structure that is returned
  172.  * via the Test_Stats system call with the NET_GET_ROUTE command.
  173.  */
  174. typedef struct Net_SpriteRoute {
  175.     int        flags;        /* Flags defined in kernel/net.h */
  176.     int        spriteID;    /* Universal Sprite Host ID */
  177.     int        type;        /* Types defined in kernel/net.h */
  178.     union {
  179.     Net_EtherHdr    etherHdr;    /* type == NET_ROUTE_ETHER */
  180.     char        data[14];    /* type == NET_ROUTE_GENERIC */
  181.     struct {
  182.         Net_EtherHdr    etherHdr;
  183.         Net_IPHeader    ipHdr;
  184.     } inetHdr;            /* type == NET_ROUTE_INET */
  185.     } route;
  186. } Net_SpriteRoute;
  187.  
  188.  
  189. /*
  190.  * Declarations for -lnet library.
  191.  */
  192.  
  193. extern Net_InetAddress    Net_StringToInetAddr _ARGS_((char *cp));
  194. extern ReturnStatus    Net_StringToAddr _ARGS_((char *buffer, int protocol,
  195.                          Net_NetworkType netType,
  196.                          Net_Address *addressPtr));
  197. extern char        *Net_InetAddrToString _ARGS_((Net_InetAddress address,
  198.                               char *buffer));
  199. extern char        *Net_AddrToString _ARGS_((Net_Address *netAddressPtr,
  200.                           int protocol,
  201.                           Net_NetworkType netType,
  202.                           char *buffer));
  203. extern unsigned int    Net_StringToNetNum _ARGS_((char *cp));
  204. extern unsigned int    Net_InetAddrHostNum _ARGS_((Net_InetAddress inetAddr));
  205. extern unsigned int    Net_InetAddrNetNum _ARGS_((Net_InetAddress addr));
  206. extern unsigned int    Net_InetAddrNetMask _ARGS_((Net_InetAddress addr));
  207. extern Net_InetAddress    Net_MakeInetAddr _ARGS_((unsigned int net,
  208.                          unsigned int host));
  209. extern char    *Net_EtherAddrToString _ARGS_((Net_EtherAddress *etherAddrPtr,
  210.                            char buffer[18]));
  211. extern void    Net_StringToEtherAddr _ARGS_((char *buffer,
  212.                        Net_EtherAddress *etherAddressPtr));
  213. extern unsigned short    Net_InetChecksum _ARGS_((int len, Address bufPtr));
  214. extern unsigned short    Net_InetChecksum2 _ARGS_((int len, Address bufPtr,
  215.                            Net_IPPseudoHdr *pseudoHdrPtr));
  216.  
  217. #if BYTE_ORDER == LITTLE_ENDIAN
  218. extern unsigned int    Net_NetToHostInt _ARGS_((unsigned int longInt));
  219. extern unsigned int    Net_HostToNetInt _ARGS_((unsigned int longInt));
  220.  
  221. extern unsigned short    Net_NetToHostShort _ARGS_((unsigned short shortInt));
  222. extern unsigned short    Net_HostToNetShort _ARGS_((unsigned short shortInt));
  223. #else 
  224. #define Net_NetToHostInt(arg)    (arg)
  225. #define Net_HostToNetInt(arg)    (arg)
  226.  
  227. #define Net_NetToHostShort(arg)    (arg)
  228. #define Net_HostToNetShort(arg)    (arg)
  229. #endif
  230.  
  231.  
  232. #endif _NET_USER
  233.